package cn.aitstone.basic.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
@Component
public class SendMailUtil {

    private static JavaMailSender mailSender;

    @Autowired
    public  void setMailSender(JavaMailSender javaMailSender) {
        this.mailSender = javaMailSender;
    }

    public static void sendMail(String sendSubject, String sendText, String sendTo) throws MessagingException {


        // 1.创建复杂邮件对象
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        // 2.发送复杂邮件的工具类
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
        helper.setFrom("2874863492@qq.com");
        helper.setSubject(sendSubject);
        // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
        helper.setText(sendText,true);
        // 5.设置收件人
        helper.setTo(sendTo);
        // 6.发送邮件
        mailSender.send(mimeMessage);




    }

}
